<?php

class Action_User_Verify
{
    function execute($request)
    {
        $code = $_REQUEST['code'];
        $db = Mongo_Database::instance() -> selectCollection('user_verify');
        $item = $db -> findOne(array('_id' => $code));

        if (null == $item)
        {
            $errorCode = 'INVALID';
        }
        else
        if (time() - 24 * 60 * 60 > $item['timestamp'])
        {
            $errorCode = 'EXPIRED';
        }
        else
        {
            $user = Document::factory('user', $item['user_id']);
            $user -> set('is_verified', 1);
            $user -> save();
            $db -> remove(array('_id' => $code));
            $errorCode = 0;
        }

        $request -> response = View::render(array('errorCode' => $errorCode), 'action/user/verify.tpl');
    }

}
